<template>
	<view>
		<image src="../../static/img/loginBg.png" mode="widthFix" class="bgimgBox"></image>
		<picker @change="languageChange" :value="index" :range="languageArray">
			<view class="languageBtn">
				<view class="">{{ languageArray[index] }}</view>
				<uni-icons type="arrowdown" color="#ff" size="12"></uni-icons>
			</view>
		</picker>
		<view class="enterprise">
			<image src="../../static/img/gylogo.png" mode="widthFix"></image>
			<view class="cont">
				<view class="title">光裕集团</view>
				<view class="hint">GUANGYU GROUP</view>
			</view>
		</view>
		<view class="authority">
			<view class="authorityLogo">
				<image src="../../static/img/authorityimg_1.png" mode="widthFix"></image>
				<image src="../../static/img/authorityimg_2.png" mode="widthFix"></image>
				<image src="../../static/img/authorityimg_3.png" mode="widthFix"></image>
			</view>
			<view class="authorityInfo">Copyright © 2003 一 2011中国·光裕集困. All Rights Reserved.</view>
		</view>
		<view class="swiperBox">
			<swiper class="swiper" :indicator-dots="true">
				<swiper-item class="swiperItem">
					<!-- 门店数量不超出6个时全部显示 -->
					<view v-if="microShopList.length<=6" v-for="(item,index) in microShopList" :key="index" class="cardItem" @click="navToMicroShop(item.id)">
						<view class="title">
							{{item.name}}
						</view>
						<image src="../../static/img/category/6.png" mode="widthFix"></image>
					</view>
					<view v-if="microShopList.length>6" v-for="(item,index) in microShopList.slice(0,6)" :key="index" class="cardItem" @click="navToMicroShop(item.id)">
						<view class="title">
							{{item.name}}
						</view>
						<image src="../../static/img/category/6.png" mode="widthFix"></image>
					</view>
				</swiper-item>
				<swiper-item v-if="microShopList.length>6" class="swiperItem">
					<view v-for="(item,index) in microShopList.slice(6,12)" :key="index" class="cardItem" @click="navToMicroShop(item.id)">
						<view class="title">
							{{item.name}}
						</view>
						<image src="../../static/img/category/6.png" mode="widthFix"></image>
					</view>
				</swiper-item>
				<swiper-item v-if="microShopList.length>12" class="swiperItem">
					<view v-for="(item,index) in microShopList.slice(12,18)" :key="index" class="cardItem" @click="navToMicroShop(item.id)">
						<view class="title">
							{{item.name}}
						</view>
						<image src="../../static/img/category/6.png" mode="widthFix"></image>
					</view>
				</swiper-item>
			</swiper>
		</view>



	</view>
</template>

<script>
	export default {
		computed: {
			i18n() {
				return this.$t('userbinding');
			}
		},
		data() {
			return {
				languageArray: ['中文', '英文', '波兰语', '俄语', '捷克语', '罗马尼亚语', '西班牙语', '匈牙利语', '越南语'],
				index: 0,

				microShopList: [],
			};
		},
		onShow() {},
		onLoad(option) {
			this.getMicroShopList();
		},
		methods: {
			getMicroShopList() {
				uni.request({
					url: 'http://121.40.82.3:52019/v1/template001/home/startHomePage', //仅为示例，并非真实接口地址。
					data: {},
					method: 'GET',
					dataType: 'json',
					header: {
						'content-type': 'application/json ' //自定义请求头信息
					},
					success: res => {
						console.log(res.data.data.microShops);
						this.microShopList = res.data.data.microShops
					}
				});
			},
			navToMicroShop(id) {
				console.log(id);
				uni.setStorageSync('microShopId', id);
				uni.switchTab({
					url: '/pages/tabBar/home/homeplus'
				});
			},
		}
	}
</script>

<style lang="scss">
	@import '../../static/css/login.scss';

	.languageBtn {
		position: absolute;
		top: 40rpx;
		right: 40rpx;
		width: 200rpx;
		height: 60rpx;
		border-radius: 40rpx;
		font-size: 24rpx;
		border: 1px solid #007aff;
		color: #007aff;
		display: flex;
		align-items: center;
		justify-content: space-around;
	}

	.enterprise {
		position: absolute;
		top: 150rpx;
		left: 40rpx;
		display: flex;
		align-items: center;

		image {
			width: 80rpx;
		}

		.cont {
			margin-left: 20rpx;

			.title {
				font-size: 40rpx;
				font-weight: bold;
			}

			.hint {
				font-size: 24rpx;
				color: #808080;
			}
		}
	}

	.authority {
		position: absolute;
		bottom: 40rpx;
		width: 100%;
		font-size: 24rpx;
		text-align: center;

		.authorityLogo {
			display: flex;
			align-items: center;
			justify-content: center;
			padding-bottom: 10rpx;

			image {
				margin: 0 20rpx;
				width: 120rpx;

				&:nth-child(2) {
					width: 50rpx;
					margin-bottom: -8rpx;
				}
			}
		}

		.authorityInfo {
			color: #ababab;
		}
	}

	.swiperBox {
		position: absolute;
		top: 300rpx;
		bottom: 200rpx;
		width: 100%;

		.swiper {
			height: 100%;
			padding: 0 40rpx;

			.swiperItem {

				.cardItem {
					float: left;
					margin-left: 2%;
					background-color: #f0eff0;
					padding: 20rpx;
					height: 200rpx;
					width: 40%;
					margin-bottom: 20rpx;
					border-radius: 20rpx;
					display: flex;
					align-items: center;
					justify-content: center;

					&:nth-child(2n) {
						margin-left: 5%;
					}

					.title {
						font-size: 28rpx;
					}

					image {
						margin-left: 20rpx;
						width: 100rpx;
					}
				}
			}
		}
	}
</style>
